/*
 * $Id: FileDownloadValidator.java,v 1.3 2009/05/19 04:06:40 afaichun Exp $
 * 
 * Copyright (C) 2008 General Electric Company. All Rights Reserved.
 * 
 * This software is the confidential and proprietary information of the General
 * Electric Company (GE). You shall not disclose this software and shall use it
 * only in accordance with the terms of the license agreement you entered into
 * with GE.
 * 
 * GE MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
 * NON-INFRINGEMENT. GE SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
 * AS A RESULT OF USING, MODIFYING, OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES.
 */
package com.ge.healthcare.autosc.onwatch.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;

import com.ge.healthcare.autosc.onwatch.bean.BaseInfoBean;
import com.ge.healthcare.autosc.onwatch.bean.FileDownloadBean;

public class FileDownloadValidator extends BasePostValidator {

	private static final String REQUEST_TYPE = "Download";
	
	public boolean supports(Class clazz) {
		return clazz.equals(FileDownloadBean.class);
	}

	public void validate(Object command, Errors errors) {
		super.validate(command, errors);

		FileDownloadBean fileDownloadBean = (FileDownloadBean)command;
		validateRequestType(fileDownloadBean, errors);
		
		ValidationUtils.rejectIfEmptyOrWhitespace(
				errors, "taskId", "required.taskId", "Task Id is required");
		
		ValidationUtils.rejectIfEmptyOrWhitespace(
				errors, "fileName", "required.filename", "File name is required");
	}
	
	private void validateRequestType(BaseInfoBean bean, Errors errors) {
		if(!REQUEST_TYPE.equalsIgnoreCase(bean.getRequestType())) {
			errors.reject("invalid.requestType", "Invalid request");
		}
	}
}
